#include "PreApplication.h"
#include "InputListener.h"

InputListener::InputListener(void)
{
}

InputListener::~InputListener(void)
{
}

bool InputListenerChain::onKeyDown(InputKey key)
{
	for(ListenerChain::iterator ite = chain.begin();ite!=chain.end();++ite)	{
		InputListener* listener = *ite;
		if(listener->onKeyDown(key))
			return true;
	}
	return false;
}

bool InputListenerChain::onKeyUp(InputKey key)
{
	for(ListenerChain::iterator ite = chain.begin();ite!=chain.end();++ite)	{
		InputListener* listener = *ite;
		if(listener->onKeyUp(key))
			return true;
	}
	return false;
}

bool InputListenerChain::onMouseDown(int x,int y,MouseButton mb,Dword flags)
{
	for(ListenerChain::iterator ite = chain.begin();ite!=chain.end();++ite)	{
		InputListener* listener = *ite;
		if(listener->onMouseDown(x,y,mb,flags))
			return true;
	}
	return false;
}

bool InputListenerChain::onMouseUp(int x,int y,MouseButton mb,Dword flags)
{
	for(ListenerChain::iterator ite = chain.begin();ite!=chain.end();++ite)	{
		InputListener* listener = *ite;
		if(listener->onMouseUp(x,y,mb,flags))
			return true;
	}
	return false;
}

bool InputListenerChain::onMouseMove(int x,int y,int deltaX,int deltaY,Dword flags)
{
	for(ListenerChain::iterator ite = chain.begin();ite!=chain.end();++ite)	{
		InputListener* listener = *ite;
		if(listener->onMouseMove(x,y,deltaX,deltaY,flags))
			return true;
	}
	return false;
}

bool InputListenerChain::onMouseWheel(int x, int y, int zDelta, Dword flags)
{
	for(ListenerChain::iterator ite = chain.begin();ite!=chain.end();++ite)	{
		InputListener* listener = *ite;
		if(listener->onMouseWheel(x,y,zDelta,flags))
			return true;
	}
	return false;
}

void InputListenerChain::push(InputListener* listener)
{
	chain.push_back(listener);
}

void InputListenerChain::clear()
{
	//for(ListenerChain::iterator ite = chain.begin();ite!=chain.end();++ite)	{
	//	InputListener* listener = ite;
	//	delete listener;
	//}
	chain.clear();
}